package Main;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	/**
	 * @param args
	 *            The arguments on application start
	 */
	public static void main(String[] args) {
		String s = (args.length > 0 ? args[0] : "");
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		RaspiServer raspiServer = new RaspiServer(s.compareTo("NO_GPIO") != 0);

		try {
			String str;

			do {
				// Wait for input
				str = br.readLine();

				// Check kick
				if (str.compareTo("kick") == 0) {
					raspiServer.server.kickClient();
					
				} else if (str.startsWith("send ")) {
					raspiServer.server.sendLine(str.substring(5, str.length()));
				}
			} while (!str.isEmpty());

		} catch (Exception e) {
			System.out.print("Exception caught in main: ");
			System.out.println(e.getMessage());
		}

		raspiServer.exit();
		System.out.println("Exit application");
		System.exit(0);
	}

}
